package Tarea3PanelY3Botones;

import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Toolkit;

import javax.swing.JPanel;

public class CreaPanel extends JPanel{
	private static int[] X;	
	private static int[] Y;	
	public static int[] Vy;
	public static int[] Vx;
	public static int[] diam; 
	private static Color[] col;
	private static Graphics2D[] gra;
	private static CrearVentana ventana;//=new CrearVentana();
	
	public static int n=3;

	public CreaPanel() {		
		setSize(400,400);		
		setBackground(Color.orange);
		DefVect();
		
	}
	private void DefVect() {
		gra=new Graphics2D[n];
		col=new Color[n];
		X=new int[n];
		Y=new int[n];
		Vx=new int[n];
		Vy=new int[n];
		diam=new int[n];
		asignar(0,1,1,3,3,170,20,50,45);
		asignar(1,300,80,3,3,77,120,90,30);
		asignar(2,5,80,7,7,86,77,150,15);
		
	}
	private void asignar(int i, int j, int k, int l, int m, int o, int p,
			int q, int r) {
		X[i]=j;
		Y[i]=k;
		Vx[i]=l;
		Vy[i]=m;
		col[i]=new Color(o,p,q);
		diam[i]=r;
		
	}
public void paint(Graphics g){
		
		super.paint(g);
		
		for (int i=0;i<n;i++){
			gra[i]=(Graphics2D)g;
			gra[i].setColor(col[i]);			
			gra[i].fillOval(X[i],Y[i],diam[i],diam[i]);	
			}	
		}
	
public void moverBolita(){		
	for (int i=0;i<n;i++){

		if (X[i] >  this.getWidth() - diam[i] ){
			Vx[i]=Vx[i]*-1;	
			if(ventana.Sonido ==true)
			Toolkit.getDefaultToolkit().beep();
		}		
		if (X[i]<0){			
			Vx[i]=Vx[i]*-1;		
			if(ventana.Sonido ==true)
				Toolkit.getDefaultToolkit().beep();
			
		}		
		if (Y[i] > this.getHeight()- diam[i]){			
			Vy[i]=Vy[i]*-1;
			if(ventana.Sonido ==true)
				Toolkit.getDefaultToolkit().beep();
		}		
		if (Y[i]<0){			
			Vy[i]=Vy[i]*-1;
			if(ventana.Sonido ==true)
				Toolkit.getDefaultToolkit().beep();
		}
			

		
		X[i]+=Vx[i];		
		Y[i]+=Vy[i];		
	}
}

}
